home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3826 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.2 KB  |  54 lines

  1. Path: rain.fr!news
  2. From: Fabien Bergeret <fbergeret@nahua.arcanet.fr>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Missinterpreting *protected* access modifier?
  5. Date: Fri, 26 Jan 96 10:38:32 WET
  6. Organization: CSI InterNetNews site
  7. Message-ID: <NEWTNews.822653031.16436.fbergeret@nahua.arcanet.fr>
  8. References: <DLrCGF.G1F@wn.planet.gen.nz>
  9. NNTP-Posting-Host: nahua.arcanet.fr
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=US-ASCII
  12. X-Newsreader: NEWTNews & Chameleon -- TCP/IP for MS Windows from NetManage
  13.  
  14.  
  15.  
  16. >      class A
  17. >      {
  18. >      protected:
  19. >        int i;
  20. >        int GetInt() { return i; };
  21. >      };
  22. >      class B : public A
  23. >      {
  24. >      protected:
  25. >        int Foo(A * pA) { return pA->GetInt(); };
  26. >      };
  27.  
  28.     Protected means that you inherit the methods. For instance, you can 
  29. have a B class :
  30.     class B : public A
  31.     {
  32.     public:
  33.         int GetIntB() 
  34.         {
  35.             return GetInt();
  36.         }
  37.     };
  38.     You call on "this" protected methods from A.
  39.     On your example, you call a method on a non-this object, in which you 
  40. cannot call GetInt, since it's not public. I don't really understand the 
  41. meaning of your B class. I woudl have written
  42.     class B : public A
  43.     {
  44.     public: 
  45.         Foo()
  46.         {
  47.             return GetInt();
  48.         }
  49.     };
  50.     
  51.     Hope thie helps
  52.  
  53.